const { cleanDatEnglishText } = require("../src/utils/datTextCleaner");

console.log("测试更新后的处理逻辑:\n");

// 测试"$you words$$$$$"格式
const specialCase = '"$you words$$$$$"';
const specialResult = cleanDatEnglishText(specialCase);

console.log(`输入: ${specialCase}`);
console.log(`输出: ${specialResult}`);
console.log("");

// 详细演示处理步骤
console.log("详细处理步骤:");
console.log(`  1. 原始文本: "${specialCase}"`);

// 第一步处理
const step1 = specialCase.replace(/([^\s]*)\$[^$]*\${4,}([^\s]*)/g, "$1$2");
console.log(`  2. 去掉$和$$$$之间的内容: "${step1}"`);

// 第二步处理特殊符号
const step2 = step1.replace(/\^/g, " ").replace(/\$/g, " ").replace(/◆/g, "");
console.log(`  3. 处理特殊符号: "${step2}"`);

// 第三步分割单词
const step3 = step2.split(" ").filter(word => word.trim() !== "");
console.log(`  4. 分割单词: [${step3.map(w => `"${w}"`).join(", ")}]`);

// 第四步去重
const cleanedWords = [];
for (let i = 0; i < step3.length; i++) {
  if (i < step3.length - 1 && step3[i].toLowerCase() === step3[i + 1].toLowerCase()) {
    cleanedWords.push(step3[i]);
    i++;
  } else {
    cleanedWords.push(step3[i]);
  }
}
console.log(`  5. 去重后: [${cleanedWords.map(w => `"${w}"`).join(", ")}]`);

// 第六步词组重复处理
let result = cleanedWords.join(" ");
result = result.replace(/(\b\w+(?:\s+\w+)*?)\s+\1\b/gi, "$1");
console.log(`  6. 词组重复处理: "${result}"`);

console.log(`  7. 最终结果: "${result.trim()}"`);
console.log("");

// 测试其他格式
const otherCases = ["^products$product$$$$$", "due to$due to$$$$$", "as soon as possible$as soon as possible$$$$$"];

console.log("其他格式测试:");
otherCases.forEach((testCase, index) => {
  const result = cleanDatEnglishText(testCase);
  console.log(`  ${index + 1}. ${testCase} -> ${result}`);
});
